package edu.spec.pms.dao.impl;

import org.madgecko.basic.dao.BaseDao;
import edu.spec.pms.dao.iface.IUserRoleDao;
import edu.spec.pms.model.sys.UserRole;
import org.springframework.stereotype.Repository;

@Repository
public class UserRoleDao extends BaseDao<UserRole> implements IUserRoleDao {

	@Override
	public void deleteByRole(int roleId) {
		String hql = "delete UserRole ur where ur.role.id=?";
		this.updateByHql(hql, roleId);
	}

	@Override
	public void deleteByUser(int userId) {
		String hql = "delete UserRole ur where ur.user.id=?";
		this.updateByHql(hql, userId);
	}

	@Override
	public void deleteByUserAndRole(Integer userId, Integer roleId) {
		String hql = "delete UserRole ur where ur.user.id=" + userId + " and ur.role.id=" + roleId;
		this.updateByHql(hql);
	}
}
